home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3757 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: cdn_news.telecom.com.au!usenet
  2. From: Jeff PAton <jpaton@vitgexec.telecom.com.au>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem...Problem!
  5. Date: 31 Jan 1996 01:25:47 GMT
  6. Organization: Telstra
  7. Message-ID: <4emger$qs@cdn_news.telecom.com.au>
  8. References: <4el09q$6im@ratree.psu.ac.th>
  9. NNTP-Posting-Host: 144.136.190.172
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15. s3610165@maliwan.psu.ac.th (Sanon CHAOCHAIYAPORN) wrote:
  16. >Dear all
  17. >        This is a iteration method program. It use to find three values, 
  18. >a b and c. This program will finish when variables, t[], are less than or 
  19. >equal an error value, ERR. But my program has not been runing. Please, 
  20. >advice me...:~( Thanks for your attention.
  21. >
  22. >Source:
  23. [snip]
  24. >main()
  25. >{
  26. [snip]
  27.  
  28. >  {
  29. [snip]
  30. >    for(i=0;i<NUM;i++)
  31. >      t[i] = v[i] - e[i];
  32. >    for(i=0;i<NUM;i++)
  33. >     e[i] = v[i];
  34. >  }while((t[0] <= ERR) && (t[1] <= ERR) && (t[2] <= ERR) && (t[3] <= ERR) &&
  35. >      (t[4] <= ERR) && (t[5] <= ERR) && (t[6] <= ERR) && (t[7] <= ERR));
  36. [snip]
  37.  
  38. Why do the while() tests use <= (less than or equal to) not >= ?? Your program
  39. probably finishes on the first time through - if one of t[] is > ERR then the
  40. while() test fails, so it finishes.
  41.  
  42. Also, a style comment - why not express your terminating condition along the lines of
  43.  
  44.     for (i= 0; i < NUM; i++)
  45.         ErrorExceeded = t[i] >= ERR;
  46.    } while (ErrorExceeded);
  47.  
  48. More compact and less prone to error if you change NUM!
  49.  
  50. Also, is the use of 8 as a divisor linked to the #define NUM 8 - if so you should
  51. probably use "/ NUM" instead of "/ 8" - makes your intention clearer
  52.  
  53.